﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using Sharebert.LinkLayerLibrary;

namespace Sharebert.OverlayLibrary.API
{
    /// <summary>
    /// Implementations of IBootstrapClient are used to communicate with the bootstrap server. After sending the PeerID to the bootstrap server,
    /// it will return with the predecessing and successing peer.
    /// By default, the bootstrap client will automatically ping the server.
    /// </summary>
    public interface IBootstrapClient
    {

        /// <summary>
        /// Requests the predecessor and successor for the calculated peer ID from the bootstrap server.
        /// </summary>
        /// <param name="peer">The peer object</param>
        /// <exception cref="NetworkException">Could not connect or sending message failed</exception>
        void RequestNeighbours(IPeer peer);

        /// <summary>
        /// Peer is going offline and tells the bootstrap server to remove him from the list.
        /// </summary>
        /// <exception cref="NetworkException">Could not connect to server or send message</exception>
        void Offline();

        /// <summary>
        /// The hostname or IP of the bootstrap server.
        /// </summary>
        string ServerAddress { get; }

        /// <summary>
        /// The port of the bootstrap server.
        /// </summary>
        int ServerPort { get; }

        /// <summary>
        /// Time in seconds, the peer will ping the bootstrap server.
        /// </summary>
        int ServerPingInverval { get; set; }

        /// <summary>
        /// Enables automatic server pinging.
        /// </summary>
        bool AutoServerPingEnabled { get; set; }

        /// <summary>
        /// Sending and receiving messages will timeout after the specified time in seconds.
        /// </summary>
        int ReadTimeout { get; set; }

        /// <summary>
        /// The server did not respond after Timeout seconds.
        /// </summary>
        event EventHandler<EventArgs> ConnectionLost;

        /// <summary>
        /// Received a peer list from the server.
        /// </summary>
        event EventHandler<NeighboursReceivedEventArgs> NeighboursReceived;

        /// <summary>
        /// The bootstrap server signals, that the choosen PeerID is already in use.
        /// </summary>
        event EventHandler<EventArgs> PeerIdInUseReceived;

    }
}
